package com.example.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.food.TakeoutMainActivity;
import com.example.home.DataAnalysis.DataAnalysisMainActivity;
import com.example.home.R;
import com.example.home.ScheduledCarInspection.ScheduledCarMainActivity;
import com.example.home.active_function.ActivityFunction;
import com.example.home.attorney.AttorneyMainActivity;
import com.example.home.bean.NewsBean;
import com.example.home.bus.BusMainActivity;
import com.example.home.film.FilmMainActivity;
import com.example.home.findWork.FindWordMainActivity;
import com.example.home.government.acivity.GovernmentMainActivity;
import com.example.home.hospital.activity.HospitalMain;
import com.example.home.house.activity.HouseActivity;
import com.example.home.inspectCar.InspectCarMainActivity;
import com.example.home.library.LibraryMainActivity;
import com.example.home.livingPayment.LivingPaymentMainActivity;
import com.example.home.logistics.LogisticsMainActivity;
import com.example.home.loveDonation.activity.CaringwelfareActivity;
import com.example.home.metro.MetroMainActivity;
import com.example.home.park.CatActivity;
import com.example.home.pet.PetMainActivity;
import com.example.home.rubbish.RubbishMainActivity;
import com.example.home.volunteer_service.VolunteerServiceMainActivity;
import com.example.home.youthstation.YouthStationActivity;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class CarAdapter extends RecyclerView.Adapter<CarAdapter.MyCarData> {
    private Context context;
    private List<NewsBean.RowsBean> list;
    private View view;

    public CarAdapter(Context context, List<NewsBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }


    public void setList(List<NewsBean.RowsBean> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public MyCarData onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充视图
        view = LayoutInflater.from(context).inflate(R.layout.item_help, null);
        return new MyCarData(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyCarData holder, int position) {
        Glide.with(context).load(ip + list.get(position).getImgUrl()).into(holder.news_img);
        holder.news_text.setText(list.get(position).getServiceName());
        int id = list.get(position).getId();
        switch (id) {
            case 17:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, CatActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 26:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, YouthStationActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 22:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, ActivityFunction.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 25:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, CaringwelfareActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 29:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, GovernmentMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 30:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, LibraryMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 20:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, HouseActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;

            case 5:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, HospitalMain.class);
                        context.startActivity(intent);
                    }
                });

                break;

            case 31:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, RubbishMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;

            case 35:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, AttorneyMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;

            case 3:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, BusMainActivity.class);
                        context.startActivity(intent);

                    }
                });
                break;
            case 18:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, FilmMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;

            case 32:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, VolunteerServiceMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 23:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, PetMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 2:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, MetroMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 24:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, LogisticsMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 9:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, InspectCarMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 7:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, LivingPaymentMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 88:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, ScheduledCarMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 27:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, DataAnalysisMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 21:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, FindWordMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 19:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, TakeoutMainActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            /*
            case 28:
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(context, LawyerActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
                */

            default:
                // 在默认情况下，显示“待开发”的提示
                holder.news_img.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "待开发", Toast.LENGTH_SHORT).show();
                    }
                });
                break;

        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyCarData extends RecyclerView.ViewHolder {
        private LinearLayout rootView;
        private ImageView news_img;
        private TextView news_text;

        public MyCarData(@NonNull View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);
            news_img = itemView.findViewById(R.id.news_img);
            news_text = itemView.findViewById(R.id.news_text);
        }
    }
}
